package com.quanquan.store.repository;

import com.quanquan.store.entity.StoreCoupon;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @ClassName:StoreCouponRepositury
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/3/20 15:42
 * @Version 1.0
 */
public interface StoreCouponRepository extends JpaRepository<StoreCoupon, String> {

    @Query(value = "SELECT * FROM oo_store_coupon WHERE store_id = ?1 AND status_show = 0 AND status_remove = 0 limit ?2,?3", nativeQuery = true)
    List<StoreCoupon> findByStoreId(String storeId, Integer count, Integer size);

    @Query(value = "SELECT * FROM oo_store_coupon WHERE coupon_id = ?1 AND status_show = 0 AND status_remove = 0", nativeQuery = true)
    List<StoreCoupon> findByCouponId(String couponId);

    @Query(value = "SELECT * FROM oo_store_coupon WHERE coupon_id = ?1 AND status_remove = 0", nativeQuery = true)
    List<StoreCoupon> findByCouponId1(String couponId);

    @Query(value = "SELECT * FROM oo_store_coupon WHERE coupon_id = ?1 and store_id = ?2 AND status_remove = 0", nativeQuery = true)
    StoreCoupon findByCouponIdAndStoreId(String couponId, String storeId);

    @Query(value = "SELECT * FROM oo_store_coupon WHERE coupon_id = ?1 AND status_show = 1 AND status_remove = 0", nativeQuery = true)
    List<StoreCoupon> queryByIdManage(String couponId);

}
